<template>
  <div class="coursecontent">
    <!-- 顶部轮播 -->
    <van-swipe class="my-swipe" :autoplay="2000" indicator-color="block">
      <van-swipe-item v-for="item in activeAdList" :key="item.id">
        <img :src="item.img" alt="1">
      </van-swipe-item>
      <!-- 底部组件 -->
    </van-swipe>
    <course-content-list
      :fetch-data="fetchData"
    ></course-content-list>
  </div>
</template>

<script>
import CourseContentList from '@/components/CourseContentList'
import { getAllAds, getQueryCourses } from '@/services/course.js'

export default {
  name: 'CourseContent',
  components: {
    CourseContentList
  },
  data () {
    return {
      // 轮播图图片列表
      adList: []
    }
  },
  created () {
    this.loadAds()
  },
  methods: {
    fetchData (options) {
      return getQueryCourses(options)
    },
    async loadAds () {
      // 此处的spacekeys：999代表首页轮播图广告位
      const { data } = await getAllAds({
        spaceKeys: '999'
      })
      this.adList = data.content[0].adDTOList
    }
  },
  computed: {
    activeAdList () {
      return this.adList.filter(item => item.status === 1)
    }
  }
}
</script>

<style>
.my-swipe{
  width: 100%;
}
.my-swipe .van-swipe-item {
  display: flex;
  justify-content: center;
  overflow: hidden;
}
.my-swipe img{
  height: 170px;
}
.course-content-list{
  top: 220px;
  bottom: 50px;
}
</style>
